package gpl.scotlandyard.beans.basics;

/** Enum of any type of ticket that could be used to move players.
 * @author Norbert Martin */
public enum Ticket {

  /** Used for bus links. */
  BUS {
    @Override
    public int getWeight() {
      return 2;
    }
  },

  /** Used for taxi, bus, underground or boat (hide) links. */
  HIDE {
    @Override
    public int getWeight() {
      return 4;
    }
  },

  /** Used for locked position. */
  NONE {
    @Override
    public int getWeight() {
      return 0;
    }
  },

  /** Used for start position. */
  START {
    @Override
    public int getWeight() {
      return 0;
    }
  },

  /** Used for taxi links. */
  TAXI {
    @Override
    public int getWeight() {
      return 1;
    }
  },

  /** Used to play 2 times with the same ticket type. */
  TWICE {
    @Override
    public int getWeight() {
      return 5;
    }
  },

  /** Used for underground links. */
  UG {
    @Override
    public int getWeight() {
      return 3;
    }
  };

  /** Returns ticket associated to s. Available for TAXI (T), BUS (B), UG (U), HIDE (H), START (S), TWICE (W), NONE (N).
   * @param s type to get
   * @return Ticket */
  public static Ticket getTypeFor(String s) {
    if ("T".equalsIgnoreCase(s) || "TAXI".equalsIgnoreCase(s)) {
      return Ticket.TAXI;
    }
    if ("B".equalsIgnoreCase(s) || "BUS".equalsIgnoreCase(s)) {
      return Ticket.BUS;
    }
    if ("U".equalsIgnoreCase(s) || "UG".equalsIgnoreCase(s)) {
      return Ticket.UG;
    }
    if ("H".equalsIgnoreCase(s) || "HIDE".equalsIgnoreCase(s)) {
      return Ticket.HIDE;
    }
    if ("S".equalsIgnoreCase(s) || "START".equalsIgnoreCase(s)) {
      return Ticket.START;
    }
    if ("W".equalsIgnoreCase(s) || "TWICE".equalsIgnoreCase(s)) {
      return Ticket.TWICE;
    }
    if ("N".equalsIgnoreCase(s) || "NONE".equalsIgnoreCase(s)) {
      return Ticket.NONE;
    }
    throw new IllegalArgumentException(s + " is not supported type");
  }

  /** Returns ticket weight.
   * @return weight */
  public abstract int getWeight();
}
